package com.app.megaprosoft.modyimcarcare;

import java.util.ArrayList;

import com.app.megaprosoft.DB.SQLiteDBClass;
import com.app.megaprosoft.DB.ServicePOS;
import com.app.megaprosoft.general.DateTime;
import com.megaprosoft.modyimcarcare.R;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;


public class Carcare_UpdateService extends Activity {
	private Button  button_cancle,
					button_status1,
					button_status2,
					button_status3,
					button_status4,
					button_status5;
	
	private TextView tv_serviceid,
					 tv_idcar;
	
	private String   CarId
					,ServiceId;
	
	
	private ListView Carcare_ServiceListView;
	
	private Handler Handler = new Handler();
	private DateTime datetime = new DateTime();
	private AlertDialog CarSearchDialog;
	//Intent
	private Intent  GetCar;
	
	ServicePOS servicepos = new ServicePOS();
	
	private CarCare_Adapter_ListService carcare_listservice_adapter;
	SQLiteDBClass myDb;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.a_carcare_dialog_statuschang);
		servicepos.setContext(getApplicationContext());
//		tv_company 	= (TextView) findViewById(R.id.a_main_company);
//		tv_username = (TextView) findViewById(R.id.a_main_username);
//		tv_defname 	= (TextView) findViewById(R.id.a_main_depart);
//		tv_date 	= (TextView) findViewById(R.id.a_main_date);
//		
//		tv_service 	= (TextView) findViewById(R.id.a_main_service);
//		tv_check	= (TextView) findViewById(R.id.a_main_check); 
//		tv_all 		= (TextView) findViewById(R.id.a_main_all);
//		
		myDb = new SQLiteDBClass(this);
		
		Bundle bundle = getIntent().getExtras();
		if (bundle != null) {
//			setCarId((String) bundle.get("CarID"));
//			setServiceId((String) bundle.get("ServiceID"));
		}
		
		
//////////////////////////////////////// Button /////////////////////////////		

//		button_cancle = (Button) findViewById(R.id.a_login_button_cancle);
//		button_cancle.setOnClickListener(text_cancle);
//		button_status1 = (Button) findViewById(R.id.a_login_status1);
//		button_status1.setOnClickListener(status1);
//		button_status2 = (Button) findViewById(R.id.a_login_status2);
//		button_status2.setOnClickListener(status2);
//		button_status3 = (Button) findViewById(R.id.a_login_status3);
//		button_status3.setOnClickListener(status3);
//		button_status4 = (Button) findViewById(R.id.a_login_status4);
//		button_status4.setOnClickListener(status4);
//		button_status5 = (Button) findViewById(R.id.a_login_status5);
//		button_status5.setOnClickListener(status5);
//		tv_serviceid   = (TextView) findViewById(R.id.tv_service_id);
//		tv_idcar	   = (TextView) findViewById(R.id.tv_car_id);
//		
//		tv_serviceid.setText(getServiceId());
//		tv_idcar.setText(getCarId());
//		
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		servicepos.setContext(getApplicationContext());
	}
	
	private OnClickListener text_cancle = new OnClickListener() {
        public void onClick(View v) {
        	onBackPressed();
        }
    };
 
    private OnClickListener status1 = new OnClickListener() {
        public void onClick(View v) {
        	try{
        		String data[][] = servicepos.SelectAll_ServicePOS("", getServiceId(),"");
//        		servicepos.UpdateServicePOS(  data[0][0], 
//	        							getServiceId(), 
//	        							"ขึ้นล้าง",
//	        							data[0][16], 
//	        							DateTime.getDateTimeNow(), 
//	        							"0", 
//	        							"0");
        	}catch(Exception e){
        		
        	} 
        	finish();
        	
        }
    };
    private OnClickListener status2 = new OnClickListener() {
    	public void onClick(View v) {
    		
        	try{
        		String data[][] = servicepos.SelectAll_ServicePOS("", getServiceId(),"");
//        		servicepos.UpdateServicePOS(  data[0][0], 
//	        							getServiceId(), 
//	        							"ล้างเสร็จ",
//	        							data[0][16], 
//	        							DateTime.getDateTimeNow(), 
//	        							"0", 
//	        							"0");
        	}catch(Exception e){
        		
        	}
        	finish();
        }
    };
//    private OnClickListener status3 = new OnClickListener() {
//    	public void onClick(View v) {
//        	try{
//        		String data[][] = servicepos.SelectAll_ServicePOS("", getServiceId(),"");
////        		servicepos.UpdateServicePOS(  data[0][0], 
////	        							getServiceId(), 
////	        							"รอตรวจสอบ",
////	        							data[0][16], 
////	        							DateTime.getDateTimeNow(), 
////	        							"0", 
////	        							"0");
////        	}catch(Exception e){
//        		
////        	}
//        	finish();
//        }
//    };
    private OnClickListener status4 = new OnClickListener() {
    	public void onClick(View v) {
        	try{
        		String data[][] = servicepos.SelectAll_ServicePOS("", getServiceId(),"");
//        		servicepos.UpdateServicePOS(  data[0][0], 
//	        							getServiceId(), 
//	        							"เช็คเรียบร้อย",
//	        							data[0][16], 
//	        							DateTime.getDateTimeNow(), 
//	        							"0", 
//	        							"0");
        	}catch(Exception e){
        		
        	}
        	finish();
//        	newActivity = new Intent(getContext(),Carcare_Login.class);
//			startActivity(newActivity);
//            finish();
//    
        }
    };
    
    private OnClickListener status5 = new OnClickListener() {
    	public void onClick(View v) {
//        	try{
//        		String data[][] = servicepos.SelectAll_ServicePOS("", getServiceId(),"");
//        		servicepos.UpdateServicePOS(  data[0][0], 
//	        							getServiceId(), 
//	        							"ตรวจปล่อย",
//	        							data[0][16], 
//	        							DateTime.getDateTimeNow(), 
//	        							"0", 
//	        							"1");
//        	}catch(Exception e){
//        		
//        	}
//        	finish();
////        	newActivity = new Intent(getContext(),Carcare_Login.class);
////			startActivity(newActivity);
////            finish();
//    
        }
    };
    
    @Override
	public void onBackPressed() {
	  
	        new AlertDialog.Builder(this)
	        .setTitle("ยกเลิกการทำรายการ")
	        .setIcon(R.drawable.erroralert)
	        .setMessage("ต้องการยกเลิกการทำรายการ")
	                .setNegativeButton(android.R.string.yes, new DialogInterface.OnClickListener() {

	                    public void onClick(DialogInterface arg0, int arg1) {
//	                    	Intent newActivity = new Intent(Carcare_StatusChange.this,Carcare_Login.class);
//	            			startActivity(newActivity);
	                        finish();
	                    }
	                })
	                .setPositiveButton(android.R.string.no, new DialogInterface.OnClickListener() {

	                    public void onClick(DialogInterface arg0, int arg1) {
	                    	
	                    }
	                }).create().show();
	}


	public String getCarId() {
		return CarId;
	}


	public void setCarId(String carId) {
		CarId = carId;
	}


	public String getServiceId() {
		return ServiceId;
	}


	public void setServiceId(String serviceId) {
		ServiceId = serviceId;
	} 
    
					
}
